package dx.util;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 路径处理的工具类
 * create by duanx 2020/12/21
 *@classname: FileUtil
 *@author: duanx
 *@date: 2020/12/21 13:07
 **/
public class PathUtil {
    private static CharSequence separator = System.getProperty("file.separator");
    private static Logger logger = LoggerFactory.getLogger(PathUtil.class);

    /**
     * 图片路径
     * @return 各系统图片路径
     */
    @NotNull
    public static String getImgBasePath(){
        //获取操作系统名称
        String os = System.getProperty("os.name");
        String basePath;
        String windows = "win";
        if (os.toLowerCase().startsWith(windows)){
            basePath = "E:/project/image/";
        }else {
            basePath = "/home/dx/image/";
        }
        logger.debug("操作系统-==>"+os+"  基本路径-==>"+basePath+"  分隔符-==>"+separator);
        //替换成各自系统的内置分隔符
        return basePath.replace("/",separator);
    }

    /**
     * 返回一个子路径
     * @param shopId 店铺ID
     * @return 子路径
     */
    @NotNull
    @Contract(pure = true)
    public static String  getShopImagePath(long shopId){
        String imagePath = "upload/item/shop/"+shopId+"/";
        logger.debug("图片存储子路径：imagePath==>"+imagePath);
        return imagePath.replace("/",separator);
    }
}
